/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package utils;

import java.util.Collection;
import java.util.Iterator;
import java.util.Vector;
import rules.Rule;

/**
 *
 * @author Creator
 */
public class FieldAppRules {

   private int firstRuleCount = 0;
   private int lastRuleCount = 0;
   private int showRulesSize = 7;
   private int ruleSize = 0;
   private Vector rules = new Vector();

   public FieldAppRules(Collection rl){
       ruleSize = rl.size();
       rules.addAll(rl);
       setLastRuleCount(ruleSize);
   }
   public void setLastRuleCount(int count){
       if (count >=showRulesSize){
           lastRuleCount = showRulesSize;
       }else{
          lastRuleCount = count;
       }
   }
   public Collection next(){

       ++firstRuleCount;
       ++lastRuleCount;
       return rules.subList(firstRuleCount, lastRuleCount);
   }
   public boolean hasNext(){
       boolean isScr = true;


       int tempFirst = firstRuleCount;
       int tempLast = lastRuleCount;

       ++tempLast;

       if (ruleSize < showRulesSize){
           isScr = false;
       }else if (tempLast >  ruleSize){
           isScr = false;
       }
       return isScr;
   }

   public boolean hasPrevious(){

       int tempFirst = firstRuleCount;
       --tempFirst;
       if (tempFirst >= 0){
         return true;
       }
       return false;
   }

  
   public Collection previous(){   
      --firstRuleCount;
      --lastRuleCount;
      return rules.subList(firstRuleCount, lastRuleCount);
   }
   /*
    public boolean isScrollbar(){

       boolean isScr = true;

       if (ruleSize < showRulesSize){
           isScr = false;
       }else if (lastRuleCount >=  ruleSize){
           isScr = false;
       }else if (firstRuleCount == 0){
           isScr = false;
       }
       return isScr;
   }
    */
   public int getShowRulesSize(){
       return showRulesSize;
   }

   public void  setShowRulesSize(int size){
       showRulesSize = size;
   }
   public Collection getAktRules(){
       return rules.subList(firstRuleCount, lastRuleCount);
   }
   public Collection getAllRules(){
       return rules;
   }
   public int getRuleSize(){
       return ruleSize;
   }
   public String toString(){

       String str="";

       Iterator itr = getAktRules().iterator();

       while(itr.hasNext()){
           Rule r = (Rule)itr.next();
           str += r.getName()+"\n";
       }
       return str;

   }

}
